package com.bright.hxj.qchz.service;

import com.bright.hxj.qchz.pojo.bo.DuijieReturnMsg;
import com.bright.hxj.qchz.pojo.command.SubmitTaskCommand;
import com.bright.hxj.qchz.pojo.po.TaskAsync;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @Author hxj
 * @Date 2025/1/7 11:42
 * @Description
 */
public abstract class AbstractSubmitTaskService implements SubmitTaskService {

    @Override
    public DuijieReturnMsg submitTaskAndSave(SubmitTaskCommand command) {
        TaskAsync taskAsync = new TaskAsync();
        taskAsync.setTaskId(command.getTaskId());
        taskAsync.setUserName(command.getUser().getUserName());
        taskAsync.setMethodName(command.getMethodName());
        taskAsync.setYears(command.getYears());
        taskAsync.setZtId(command.getZtId());
        taskAsync.setRunFlag(true);
        taskAsync.setStatus(TaskManager.ASYNC_TASK_WAITING);
        taskAsync.setCreator(taskAsync.getUserName());
        taskAsync.setJsonData(command.getJsonObject().toString());

        // 提交任务的具体实现
        DuijieReturnMsg returnMsg = submitTask(command, taskAsync);
//        // 如果成功 插入数据到表里
//        if (DuijieReturnMsg.isSuccess(returnMsg)) {
//            TaskManager taskManager = command.getTaskManager();
//            returnMsg = taskManager.insertTaskToDB(taskAsync);
//            if (DuijieReturnMsg.isSuccess(returnMsg)) {
//                System.out.println(command.getTaskId() + "创建任务成功，程序返回！");
//                returnMsg.setData(command.getTaskId());
//            }
//        }
        return returnMsg;
    }

    protected abstract DuijieReturnMsg submitTask(SubmitTaskCommand command, TaskAsync taskAsync);

}
